package com.xm.settlement.service.impl;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.plugins.Page;
import com.xm.settlement.commons.utils.PageInfo;
import com.xm.settlement.mapper.AppCarouselFigureMapper;
import com.xm.settlement.model.AppCarouselFigure;
import com.xm.settlement.service.IAppCarouselFigureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 *  AppCarouselFigure 表数据服务层接口实现类
 *
 */
@Service
public class AppCarouselFigureServiceImpl extends SuperServiceImpl<AppCarouselFigureMapper, AppCarouselFigure> implements IAppCarouselFigureService {

    @Autowired
    private AppCarouselFigureMapper appCarouselFigureMapper;


    @Autowired
    private IAppCarouselFigureService appCarouselFigureService;


    @Override
    public void selectDataGrid(PageInfo pageInfo) {
        Page<AppCarouselFigure> page = new Page<AppCarouselFigure>(pageInfo.getNowpage(), pageInfo.getSize());
        List<AppCarouselFigure> list = appCarouselFigureMapper.selectAppCarouselFigureList(page);
        pageInfo.setRows(list);
        pageInfo.setTotal(page.getTotal());
    }


    @Override
    public Integer addForm(AppCarouselFigure appCarouselFigure, String type){
       List<Integer> idx = appCarouselFigureMapper.selectIndex(type);
        for(Integer index : idx){
            if(index.equals(appCarouselFigure.getIndex())){
                return 0;
            }
        }
            appCarouselFigureService.insert(appCarouselFigure);
            return 1;
    }
}